package com.nwpu.am.config;


import com.nwpu.am.utils.id_generator.IdGenerator;
import com.nwpu.am.utils.id_generator.SnowflakeIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * IdGeneratorConfig
 *
 * @author Roy
 * @version 1.0
 * {@code @date} 2024/6/6
 */

@Configuration
@Slf4j
public class IdGeneratorConfig {
    @Value("${am.snowflake.work-id}")
    private long workId;
    @Value("${am.snowflake.data-center-id}")
    private long dataCenterId;

    @Bean(name = "idGenerator")
    public IdGenerator snowflakeIdGenerator(SnowflakeIdGenerator generator) {
        log.info("准备id生成器。。。");
        generator.init(workId, dataCenterId);
        return generator;
    }
}
